/*
 * HAPSIEAgregaArea.java
 *
 * Created on 24/01/2012, 08:44:50 PM
 */
package interfaz.gestionAreas;

import interfaz.Intro.MenuPrincipal;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author Erika Berenice Hernandez Angulo
 */
public class AgregaArea extends javax.swing.JDialog {

    int indice = 0;
    List listAreas = MenuPrincipal.manAreas.getFullAreas();  
    
    /** Creates new form HAPSIEAgregaArea */
    public AgregaArea(java.awt.Dialog parent) {
        super(parent);
        initComponents();
    }
    
    public AgregaArea(java.awt.Dialog parent, int indice){
        super(parent);
        initComponents();
        this.indice = indice;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        textoArea = new javax.swing.JTextField();
        textoEncargado = new javax.swing.JTextField();
        botonGuardarArea = new javax.swing.JButton();
        botonCancelarArea = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(AgregaArea.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        textoArea.setText(resourceMap.getString("textoArea.text")); // NOI18N
        textoArea.setName("textoArea"); // NOI18N

        textoEncargado.setText(resourceMap.getString("textoEncargado.text")); // NOI18N
        textoEncargado.setName("textoEncargado"); // NOI18N

        botonGuardarArea.setFont(resourceMap.getFont("botonGuardarArea.font")); // NOI18N
        botonGuardarArea.setText(resourceMap.getString("botonGuardarArea.text")); // NOI18N
        botonGuardarArea.setName("botonGuardarArea"); // NOI18N
        botonGuardarArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonGuardarAreaActionPerformed(evt);
            }
        });

        botonCancelarArea.setFont(resourceMap.getFont("botonCancelarArea.font")); // NOI18N
        botonCancelarArea.setText(resourceMap.getString("botonCancelarArea.text")); // NOI18N
        botonCancelarArea.setName("botonCancelarArea"); // NOI18N
        botonCancelarArea.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarAreaActionPerformed(evt);
            }
        });

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setIcon(resourceMap.getIcon("jLabel4.icon")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(370, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addGap(25, 25, 25))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(botonGuardarArea, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(186, 186, 186)
                .addComponent(botonCancelarArea, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                .addGap(38, 38, 38))
            .addGroup(layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 183, Short.MAX_VALUE)
                        .addComponent(jLabel4)
                        .addGap(24, 24, 24))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(textoEncargado, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(textoArea, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 277, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel4)
                        .addGap(65, 65, 65))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addGap(29, 29, 29)
                        .addComponent(textoArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(3, 3, 3)))
                .addGap(25, 25, 25)
                .addComponent(jLabel2)
                .addGap(28, 28, 28)
                .addComponent(textoEncargado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(55, 55, 55)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonCancelarArea, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botonGuardarArea, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
private void botonCancelarAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarAreaActionPerformed
    int  response = JOptionPane.showConfirmDialog(this, "¿Realmente desea salir?");
    if(response == JOptionPane.YES_OPTION) {
        getOwner().setVisible(true);
        this.setVisible(false);
    }
}//GEN-LAST:event_botonCancelarAreaActionPerformed

private void botonGuardarAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGuardarAreaActionPerformed

   if(textoArea.getText().trim().equals("")){
       JOptionPane.showMessageDialog(this, "Los campos están vacios!!");       
   } else{
       int response = JOptionPane.showConfirmDialog(this, "¿Desea guardar los cambios?");  
       if(response == JOptionPane.YES_NO_OPTION){
           MenuPrincipal.manAreas.creaYGuardaArea(textoArea.getText(), textoEncargado.getText());    
           ((GestionDeAreas) getOwner()).listAreas = MenuPrincipal.manAreas.getFullAreas();
           ((GestionDeAreas) getOwner()).actualizaTabla();
           getOwner().setVisible(true);
           this.setVisible(false);
       } else {
           getOwner().setVisible(true);
           this.setVisible(false);
       }
  }
}//GEN-LAST:event_botonGuardarAreaActionPerformed

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    int response = JOptionPane.showConfirmDialog(this, "¿Realmente desea salir?");
    if(response == JOptionPane.YES_OPTION) {
        getOwner().setVisible(true);
        this.setVisible(false);
    }
}//GEN-LAST:event_formWindowClosing

    /**
     * @param args the command line arguments
     */
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonCancelarArea;
    private javax.swing.JButton botonGuardarArea;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField textoArea;
    private javax.swing.JTextField textoEncargado;
    // End of variables declaration//GEN-END:variables

}
